﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace AssistCore
{
    public struct Rect
    {
        public int Left;
        public int Top;
        public int Right;
        public int Bottom;
    }
    public struct POINT
    {
        public int X;
        public int Y;
    }
    public class Win32Core
    {
        public delegate bool EnumWindowsProc(int hWnd, int lParam);

        [DllImport("User32.dll", EntryPoint = "GetKeyState")]
        public static extern short GetKeyState(int nVirtKey);
        [DllImport("user32.dll")]
        public static extern int EnumWindows(EnumWindowsProc ewp, int lParam);
        [DllImport("user32")]
        public static extern bool RegisterHotKey(IntPtr hWnd, int id, int modkey, int vk);
        [DllImport("user32")]
        public static extern bool UnregisterHotKey(IntPtr hWnd, int id);

        [DllImport("kernel32")]
        public static extern System.IntPtr LoadLibrary(string dllfile);

        [DllImport("kernel32")]
        public static extern System.IntPtr GetProcAddress(System.IntPtr hModule, string lpProcName);

        [DllImport("kernel32")]
        public static extern bool FreeLibrary(IntPtr hModule);
        [DllImport("user32")]
        public static extern IntPtr GetForegroundWindow();

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

        [DllImport("user32")]
        public static extern int GetWindowRect(IntPtr hwnd, out Rect lpRect);
        [DllImport("kernel32.dll")]
        public static extern int GetPrivateProfileInt(string lpAppName,string lpKeyName,int nDefault,string lpFileName);

        [DllImport("kernel32.dll")]
        public static extern int GetPrivateProfileString(string lpAppName, string lpKeyName,string lpDefault,StringBuilder lpReturnedString,int nSize,string lpFileName);

        [DllImport("kernel32.dll")]
        public static extern int WritePrivateProfileString(string lpAppName,string lpKeyName,string lpString,string lpFileName);
        /// <summary>
        /// 最大化、最小化、正常化窗口
        /// </summary>
        /// <param name="hwnd">窗口句柄</param>
        /// <param name="nCmdShow">正常1，最小化2，最大化3</param>
        /// <returns></returns>
        [DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
        public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
        
        [DllImport("user32.dll")]
        public static extern IntPtr WindowFromPoint(System.Drawing.Point p);

        [DllImport("user32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool GetCursorPos(out System.Drawing.Point p);
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetForegroundWindow(IntPtr hWnd);

    }
}
